<script type="text/javascript" src="<?=base_url()?>js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="<?=base_url()?>js/jquery.tablednd_0_5.js"></script>
<div id="mainContent">
	<center><h2>จัดลำดับรายชื่อโรงเรียน เพื่อใช้กับหน้า hall of frame</h2></center><hr/>
	<?=form_open('present_student/saveSchoolOrder')?>
		<input type="hidden" name="stuid" id="stuid" />
		<table id="stuTable" width="300px" align="center" cellpadding="0" cellspacing="0" style="border: 1px solid #0000FF; background-color: #FFFFFF">
			<thead>
 			<tr bgcolor="#000974">
 				<td width="40px">&nbsp;</td>
				<td><div align="center" style="color:#FFFFFF;"><strong>ชื่อโรงเรียน</strong></div></td>
	      		<td><div align="center" style="color:#FFFFFF;"><strong>ลำดับที่</strong></div></td>
 			</tr>
 			</thead>
 			<tbody>
 			<?php 
 				for($i = 0; $i < count($data); $i++) {
 					if($i % 2 == 0) {
 						echo "<tr id='$i'>";
 					} else {
 						echo "<tr id='$i' bgcolor='#C6E2FF'>";
 					}?>
 				<td class="dragHandle">&nbsp;</td>
 				<td><div align="left"><input type="text" name="sc_name[]" value="<?php echo $data[$i]->school_name;?>">  </div></td>
		 	  	<td><div align="center">
		 	    	<input name="txtSeq[]" type="text" id="txtSeq<?php echo $i;?>" value="<?php echo $data[$i]->seq;?>" size="3" readonly="readonly" class="textReadonly"/>
		 	    	<input type="hidden" name="sid[]" id="stuid<?php echo $i;?>" value="<?php echo $data[$i]->order_id;?>" />
		      	  </div></td>
		 	  	</tr>	
 			<?php } ?>
 			</tbody>
		</table>
<br />
<div align="center">
<input name="btnSubmit" type="submit"  value="บันทึกข้อมูล" />
</div>
<script type="text/javascript">

	$(document).ready(function() {
		$("#stuTable tr").hover(function() {
	          $(this.cells[0]).addClass('showDragHandle');
	    }, function() {
	          $(this.cells[0]).removeClass('showDragHandle');
	    });
			
		$("#stuTable").tableDnD({
		    onDrop: function(table, row) {
				objArr = document.getElementsByName('txtSeq[]');
				if(objArr != null && objArr.length > 0) {
					for(i = 0; i < objArr.length; i++) {
						objArr[i].value = i+1;
					}
				}
		    }, 
		    dragHandle: "dragHandle"
		});
		    
	});

	function toBlack(obj) {
		obj.src = '<?=base_url()?>images/detail_b.png';
	}
	function toColor(obj) {
		obj.src = '<?=base_url()?>images/detail.png';
	}
	function setStuID(obj) {
		document.getElementById('stuid').value = obj.value;
	}
</script>
	<?=form_close();?>
</div>
